<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('表格父子视图')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
<!--		<div class="col-sm-12 search-collapse">
			<form id="formId">
				<div class="select-list">
					<ul>
						<li>
							产品名称：<select id="productname"></select>
						</li>
					</ul>
				</div>
			</form>
		</div>-->

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-success" onclick="add()" shiro:hasPermission="system:smsphone:add">
				<i class="fa fa-plus"></i> 添加
			</a>
		</div>
		<div class="col-sm-12 select-table table-striped">
			<!-- 点击事件的方式打开使用 detailViewIcon: false and detailViewByClick: true
                 data-detail-view-icon="false"
                 data-detail-view-by-click="true" -->
			<table id="bootstrap-table"></table>
		</div>
	</div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
	var prefix = ctx + "product/product";
	var datas = [[${@dict.getType('sys_normal_disable')}]];

	$(function() {
		var options = {
			url: prefix + "/listsms",
			showSearch: false,
			showRefresh: false,
			showToggle: false,
			showColumns: false,
			detailView: true,
			onExpandRow : function(index, row, $detail) {
				initChildTable(index, row, $detail);
			},
			columns: [{
				checkbox: true
			},
				{
					field : 'id',
					title : 'ID',
					visible: false
				},
				{
					field : 'productName',
					title : '产品名称'
				},
				{
					field : 'nameRule',
					title : '命名规则'
				},
				{
					field : 'createDate',
					title : '创建时间'
				},
				{
					field: 'isOpen',
					title: '是否启用',
					align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
				},
			/*	{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs" href="javascript:;"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-danger btn-xs" href="javascript:;"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
					}
				}*/]
		};
		$.table.init(options);
	});
	var prefixphone = ctx + "system/smsphone";
	initChildTable = function(index, row, $detail) {
		console.log("fuzhi")
		var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
		$(childTable).bootstrapTable({
			url: prefixphone + "/list",
			method: 'post',
			sidePagination: "server",
			contentType: "application/x-www-form-urlencoded",
			queryParams : {
				productId: row.id
			},
			columns: [{
				field : 'id',
				title : '子表ID',
				visible: false

			},
				{
					field : 'name',
					title : '名称'
				},
				{
					field : 'phone',
					title : '电话'
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-danger btn-xs" onclick="deletedata('+row.id+')" "><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
					}
				}]
		});
	};
	function add(){
		$.modal.openTab("添加",prefixphone + "/add/"+$("#productname").val());
	}
	function statusTools(row) {
		if (row.isstop == 0) {//开启
			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';//点击关闭
		} else {//关闭
			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';//点击开启
		}
	}
	/* 关闭 */
	function disable(id) {
		$.modal.confirm("确认要关闭用户吗？", function() {
			$.operate.post(prefixphone + "/changeStatuscp", { "id": id, "status": 0 });
		})
	}
	/* 启用 */
	function enable(id) {
		$.modal.confirm("确认要启用用户吗？", function() {
			$.operate.post(prefixphone + "/changeStatuscp", { "id": id, "status": 1 });
		})
	}
	function deletedata(id){
		$.modal.confirm("确认要删除这条数据吗?", function() {
			$.operate.post(prefixphone + "/remove", { "ids": id});
		});
	}
</script>
</body>
</html>